home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-09-14 | 5.8 KB | 169 lines | [TEXT/KAHL] |
- /*
- bitmap w/unique clip.c
-
- This file demonstrates the ability of QuickDraw GX to clip any shape with any geometric shape. In this case, we
- retrieve a bitmap shape from the resource fork of the application, and clip it with a text shape - "BEACH". We collect
- both shapes into a GX picture, thereby allowing us to make one call to draw both shapes.
-
- NOTES:
- • This file requires the following files to run correctly:
- "graphics shell.c", "font library.c", "graphics debug library.c", "qd library.c",
- "color library.c", and "transform library.c".
-
- • For the best printing results, print this file in "landscape".
-
- ©1992 - 1993 Apple Computer, Inc.
- All rights reserved.
- */
-
- #include <events.h>
- #include <windows.h>
-
- #include "Font library.h"
- #include "graphics debugging.h"
- #include "graphics libraries.h"
- #include "graphics toolbox.h"
- #include "qd library.h"
- #include "graphics shell.h"
-
- //
- // Define "DEBUG" if you want validation of our bitmap shape when we read it in from the app's resource fork. Validation
- // will only work with the "debugging" extension. If you make the call without the "debugging" extension, you will just
- // return without any problems.
- //
- #define DEBUG
-
- /** Set up the title and size of the window **/
- Str255 gWindowTitle = "\p bitmap shape with unique clip ";
- Rect gWindowQDRect = {50, 20, 475, 475};
-
- /**
- If gDebugging = TRUE, graphics library errors and notices will be posted. This functionality will only work with
- the "debugging" version of the QuickDraw GX init. If this version of the init is not installed, nothing bad will happen,
- but these functions will not work.
- **/
- Boolean gDebugging = true;
-
-
- /** Set "gGiveMeValidation" to TRUE, if you will receive run-time validation. **/
- Boolean gGiveMeValidation = true;
-
-
- /**
- gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
- in main () within graphics shell.c. You can determine the amount of graphics gxHeap required by using GraphicsBug.
- With gGraphicsHeapSize set to 25k, I had 2 free blocks left in the graphics gxHeap. Sounds good to me.
- **/
- long gGraphicsHeapSize = 325;
-
- gxShape gthePicture;
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization(gWindow)
- WindowPtr gWindow;
- {
- gxShape newClipShape;
- gxShape tempBitmapShape;
- gxPoint textPostion = {ff(1), ff(65)};
-
- InitCommonColors ();
-
- gthePicture = GXNewShape(gxPictureType);
- GXSetShapeAttributes(gthePicture, gxUniqueItemsShape);
-
- //
- // Define the shape to clip our bitmap shape with. In this case, our clip shape will be a text shape which uses a
- // text size of 96 point and the Helvetica font. We scale the sahpe up to fit the bitmap shape. The scaling could have
- // been perfomred by getting the bounds og the text and bitmap shape and scling for the difference. You can get
- // the bounds of both shapes by calling GXGetShapeBounds (...).
- //
- newClipShape = GXNewText(5,(unsigned char*)"BEACH", &textPostion);
- SetShapeCommonFont(newClipShape, helveticaFont);
- GXSetShapeTextSize(newClipShape, ff(96));
- GXScaleShape(newClipShape, fl(1.20), fl(3.50), 0, 0);
- GXMoveShapeTo (newClipShape, ff(2), ff(1));
-
- //
- // Retrieve the bitmap shape form the resource fork of the application. With the "debugging" init installed, we
- // can check to see if the shape was retrieved correctly by calling the shape validation routine. If the shape is
- // not valid, we will recieve a warning in the debugger.
- //
- tempBitmapShape = GetPixMapShape(129);
-
- #ifdef DEBUG
- GXValidateShape (tempBitmapShape);
- #endif
-
- //
- // Set the clip of our bitmap shape to our tesxt shape and add it to our picture.
- //
- GXSetShapeClip(tempBitmapShape, newClipShape);
- GXMoveShape (tempBitmapShape, ff(5), ff(95));
- GXSetPictureParts(gthePicture, 0, 0, 1, &tempBitmapShape, nil, nil, nil);
-
- //
- // Change the fill of our text shape be to the outline of the text, set the size used, set the pen to cruise on the outside
- // of the contour of each letter, and add it to our picture shape.
- //
- GXMoveShape (newClipShape, ff(5), ff(95));
- GXSetShapeFill(newClipShape, gxClosedFrameFill);
- GXSetShapeStyleAttributes(newClipShape, gxOutsideFrameStyle);
- GXSetShapePen(newClipShape, ff(3));
- SetShapeCommonColor(newClipShape, blue);
-
- GXSetPictureParts(gthePicture, 0, 0, 1, &newClipShape, nil, nil, nil);
-
- //
- // We no longer need the clip or bitmap shapes because they have been copied into the picture.
- //
- GXDisposeShape (newClipShape);
- GXDisposeShape (tempBitmapShape);
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw(gWindow)
- WindowPtr gWindow;
- {
- GXDrawShape (gthePicture);
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose(gWindow)
- WindowPtr gWindow;
- {
- /**
- You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- can turn notices on in this file by setting gDebugging = TRUE (above).
- **/
- DisposeCommonColors ();
- GXDisposeShape(gthePicture);
- GXDisposeShape(gWindowBoundsShape);
- DisposeWindow(gWindow);
- }
-
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick(gWindow)
- WindowPtr gWindow;
- {
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
-
- void DoIdle(gWindow)
- WindowPtr gWindow;
- {
- }
-